import { mapGetters} from 'vuex'

export default {
  computed: {
    ...mapGetters('m_cart',['total'])
  },
  watch:{
    //监听total值的变化
    total(){
      this.setBadge()
    }
  },
  onShow(){
    this.setBadge()
  },
  methods: {
    //购物车已选商品数量
    setBadge(){
      if(this.total!==0){
        uni.setTabBarBadge({
          index:2,
          text:this.total + ''
        })
      }else{
        uni.removeTabBarBadge({
          index:2
        })
      }
    }
  }
}